package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjProductParamFieldValOption;
import com.zb.mapper.ZjProductParamFieldValOptionMapper;
import com.zb.service.ZjProductParamFieldValOptionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 产品参数字段值关联选项值表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-12-30
 */
@Service
public class ZjProductParamFieldValOptionServiceImpl extends ServiceImpl<ZjProductParamFieldValOptionMapper, ZjProductParamFieldValOption> implements ZjProductParamFieldValOptionService {

    // 根据[产品参数字段值关联表ID]查询
    @Override
    public List<ZjProductParamFieldValOption> getByProductParamFieldValIds(List<Long> productParamFieldValIds) {
        if (CollectionUtil.isEmpty(productParamFieldValIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjProductParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.select("id", "product_param_id", "product_param_field_val_id", "opt_value");
        wrapper.in("product_param_field_val_id", productParamFieldValIds);
        return this.list(wrapper);
    }

    // 根据产品参数ID删除选项值
    @Override
    public void deleteByByProductParamId(Long productParamId) {
        QueryWrapper<ZjProductParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.eq("product_param_id", productParamId);
        this.remove(wrapper);
    }

    // 根据产品参数ID批量删除选项值
    @Override
    public void deleteByByProductParamIds(List<Long> productParamIds) {
        if (CollectionUtil.isEmpty(productParamIds)) {
            return;
        }
        QueryWrapper<ZjProductParamFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.in("product_param_id", productParamIds);
        this.remove(wrapper);
    }
}
